package com.gitee.ywj1352.reactor;

import org.junit.Assert;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;

import java.time.Duration;


/**
 *     Subscription 接口定义了连接发布者和订阅者的方法
 *     Publisher<T> 接口定义了发布者的方法
 *     Subscriber<T> 接口定义了订阅者的方法
 *     Processor<T,R> 接口定义了处理器
 */
public class Learning02 {

    @Test
    public void fun1() throws InterruptedException {
        Flux.interval(Duration.ofSeconds(1), Duration.ofSeconds(1)).subscribe(System.out::println);
        Thread.sleep(5000);
    }

    /**
     * how to ut
     */
    @Test
    public void test() {
        Flux<Integer> just = Flux.just(1, 2, 3);
        StepVerifier.create(just)
            .assertNext(integer -> {
                Assert.assertEquals(1, integer.intValue());
            }).assertNext(integer -> {
            Assert.assertEquals(2, integer.intValue());
        }).assertNext(integer -> {
            Assert.assertEquals(4, integer.intValue());
        }).verifyComplete();
    }

}
